using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using EntLibContrib.PolicyInjection.CallHandlers;

namespace EntLibContrib.PolicyInjection.Configuration
{
    [Assembler(typeof(SynchronizedCallHandlerAssembler))]
    public class SynchronizedCallHandlerData : CallHandlerData
    {
        /// <summary>
        /// Construct a new <see cref="SynchronizedCallHandlerData"/>.
        /// </summary>
        public SynchronizedCallHandlerData()
        {
        }

        /// <summary>
        /// Construct a new <see cref="SynchronizedCallHandlerData"/>.
        /// </summary>
        /// <param name="handlerName">Name of the handler.</param>
        public SynchronizedCallHandlerData(string handlerName)
            : base(handlerName, typeof(SynchronizedCallHandler))
        {
        }
    }

    /// <summary>
    /// Class used by ObjectBuilder to construct an <see cref="SynchronizedCallHandler"/> from
    /// a <see cref="SynchronizedCallHandlerData"/> instance.
    /// </summary>
    public class SynchronizedCallHandlerAssembler : IAssembler<ICallHandler, CallHandlerData>
    {
        /// <summary>
        /// Builds an instance of the subtype of <typeparamref name="TObject"/> type the receiver knows how to build,  based on 
        /// an a configuration object.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of the <typeparamref name="TObject"/> subtype.</returns>
        public ICallHandler Assemble(IBuilderContext context, CallHandlerData objectConfiguration,
                                     IConfigurationSource configurationSource,
                                     ConfigurationReflectionCache reflectionCache)
        {
            return new SynchronizedCallHandler();
        }
    }
}
